package com.kanavi.stand.task;

import com.kanavi.stand.entity.SysLog;
import com.kanavi.stand.service.SysLogService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author hailan
 * @version 1.0
 * @className AsyncTask
 * @description TODO
 * @date 2020-09-02 22:00
 */
@Component
@Async("taskExecutor")
public class AsyncTask {

    @Resource
    private SysLogService sysLogService;

    //获取异步结果
    public void task4(SysLog sysLog) throws InterruptedException{
        long begin = System.currentTimeMillis();
        sysLogService.save(sysLog);
        System.out.println("当前线程"+Thread.currentThread().getName());
//        Thread.sleep(2000L);
        long end = System.currentTimeMillis();
        System.out.println("任务4耗时="+(end-begin));
    }


//    public Future<String> task5() throws InterruptedException{
//        long begin = System.currentTimeMillis();
//        Thread.sleep(3000L);
//        long end = System.currentTimeMillis();
//        System.out.println("任务5耗时="+(end-begin));
//        return new AsyncResult<String>("任务5");
//    }
//
//    public Future<String> task6() throws InterruptedException{
//        long begin = System.currentTimeMillis();
//        Thread.sleep(1000L);
//        long end = System.currentTimeMillis();
//        System.out.println("任务6耗时="+(end-begin));
//        return new AsyncResult<String>("任务6");
//    }

}
